package com.lgc.webtest.mq.consumer;

import com.lgc.webtest.configuration.RabbitMQConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 此种消费，在类上加@RabbitListener，在方法上加@RabbitHandler
 *
 * @RabbitListener除了可以作用在方法，也可以作用在类上。在后者的情况下，需要在处理的方法使用@RabbitHandler。一个类可以配置多个@RabbitHandler
 */
@RabbitListener(queues = RabbitMQConfig.QUEUE_NAME)
@Slf4j
@Component
public class HelloReceiver {
    @RabbitHandler
    public void process(String message) {
        try {
            Thread.sleep(1);

            int a = 1;
            int b = 0;
            int c = a / b;
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (Exception e) {
            //e.printStackTrace();
            log.info(String.format("receive message process: %s", "exception"));
            throw e;
        }
        log.info(String.format("receive message process: %s", message));
    }
}
